package soccerscope.daistatistic.tools;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;

/**
 * 
 * a jpg writer
 */
public class JPGWriter {

  /**
   * 
   * saves an image to a file
   * 
   * @param BufferedImage
   *          the image to save
   * @param String
   *          the file name without the .jpg extension
   */
  public static void save(BufferedImage img,
      String nameWithoutExtension) throws Exception {

//    ByteArrayOutputStream out = new ByteArrayOutputStream(0xfff);
//    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//
//    JPEGEncodeParam param;
//    param = encoder.getDefaultJPEGEncodeParam(img);
//    param.setQuality(1f, true);
//
//    encoder.encode(img, param);
//
//    FileOutputStream fos = new FileOutputStream(nameWithoutExtension + ".jpg");
//    fos.write(out.toByteArray());
//    fos.close();
//    out.close();
  }

  /**
   * 
   * writes some text lines inton an image
   * 
   * @param String[]
   *          the text lines
   * @param BufferedImage
   *          the image
   * @return BufferedImage the image now with the textlines
   */
  public static BufferedImage writeStringsToImage(String[] textLines,
      BufferedImage image) {

    // get the graphic context from the image
    Graphics g = image.createGraphics();
    g.setColor(Color.WHITE);

    // get y dimension
    int y = image.getHeight() - 2;

    // write the text lines to the image from south to north
    for (int i = 0; i < textLines.length; i++) {
      if (y > 0) {
        g.drawString(textLines[i], 5, y);
      }
      y = y - 14;
    }

    return image; // return an image
  }
}

/**
 * $Log: JPGWriter.java,v $ Revision 1.2 2006/11/05 13:58:03 wetzker more
 * merging - CLang + MF + some states still missing
 * 
 * Revision 1.1.28.2 2006/07/31 13:36:25 endert Added Java-Doc to constructors
 * if missing, minor refactorings. Revision 1.1.28.1 2006/07/26 15:28:31 endert
 * Formatted Code Revision 1.1 2006/03/13 07:38:15 axle moved from ROOT/src for
 * Maven 2 Buildsystem and Team/Soccerscope separation
 * 
 * Revision 1.3 2006/02/22 16:05:11 endert This is done: - Rebound SoccerScope
 * to Agents (can be added or removed in config-file) - Situations now all
 * extend abstract class Situation - Refactorings: ActionBean _ removed from
 * Attributes - SoccerScope will automatically connect to host given in
 * Start-Call - Trainer uses the same host as soccerscope - Removed unused stuff
 * (old confs, bat, etc.) - Code formatted (good luck when merging) - organized
 * imports - all that i forgot to mention here Revision 1.2 2005/06/20 17:30:24
 * andpaul documentation
 * 
 * Revision 1.1 2005/04/20 10:40:17 endert Fresh Team Repository installation
 * from /home/e/endert/Robocup to here.
 * 
 * Revision 1.2 2005/04/12 12:38:47 andpaul time again for code documentation -
 * same.Chart; same.XYDatasets; PosDifChart;StaminaChart and ViewAngleChart are
 * depricated. Will deleted if statistic dialog layout is final.
 * 
 * Revision 1.1 2005/04/02 11:15:32 andpaul setting up the .jpg file writer
 * 
 * 
 * 
 */
